import { useMemo } from "react";
import { LoginReducer } from "../data/Login";

const { useViewState } = LoginReducer;

export const useAdminName = () => {
    const { state } = useViewState();
    return useMemo(() => state.adminData?.userName ??  state.adminData?.name , [state]);
};

export const useTableData = <T>(data: T[], fn?: Function): (T & {key: string})[] => {
    return useMemo(() => data.map((item,index) => {
        const updateItem = typeof fn === "function" ? fn(item) : item;
        return {
            key: index.toString(),
            ...updateItem
        }
    }), [data]);
}